<?php
class UserToken extends UserTokenPeer
{
	function UserToken()
	{
		parent::UserTokenPeer();
	}
	
	
	function generate($text)
	{
		$token = sha1($text);
		$this->settoken($token);
	}
	
	
	public static function getTokenForUser($user_id)
	{
		$db = new Database();
		$query = "SELECT id From user_token WHERE user_id = $user_id";
		$db->query($query);
		$result = $db->result;
		$id = mysql_fetch_row($result);
		if (isset($id[0])) {
			$token = new UserToken();
			$token->select($id[0]);
			return $token;
		}

		return null;
	}
}
?>